import Qt 4.7
import "../js/snr-app.js" as APP

Item {
    id: container;

    signal clicked();

    width: APP.buttonWidth
    height: APP.buttonHeight

    property string buttonText;
    property string buttonImage
    property string buttonTextColor
    property string buttonImagePressed
    property string buttonTextColorActive: APP.buttonTextColorActive
    property string buttonTextColorPressed:APP.buttonTextColorPressed
    property bool disabled: false


    BorderImage {
        id: btnImage;
        anchors.fill: parent
        source: APP.getProjectImage(buttonImage)
    }
    MouseArea {
        id: mouseRegion;
        anchors.fill: container;
        onClicked: {
            container.clicked();
        }
    }

    Text {
        id: btnText;
        color: buttonTextColor;
        anchors.centerIn: btnImage;
        font.bold: false
        font.pixelSize: 22 * APP.scale;
        text: container.buttonText
    }

    states: [
        State {
            name: "disabled"
            when: disabled
            PropertyChanges {
                target: container
                opacity: 0.3
            }
        },
        State {
            name: "enabled"
            PropertyChanges {
                target: btnImage
                source: APP.getProjectImage(buttonImage)
            }
            PropertyChanges {
                target: btnText
                color: buttonTextColor
            }
        },

        State {
            name: "pressed"
            when: mouseRegion.pressed == true && !disabled
            PropertyChanges {
                target: btnText
                color: buttonTextColorPressed
            }
            PropertyChanges {
                target: btnImage
                source: APP.getProjectImage(buttonImagePressed)
            }
        }
    ]
}
